<?php
namespace app\app\controller\v1;
use app\app\Appbase;
use app\admin\model\SystemParamValue;

//
//会员卡
//
class MemberCard extends Appbase 
{
	
	/**
	* 获取员工预约时间
	* /app/v1/member_card/index
	* 需要登录 
	* @is_need_login true
	*/
	public function index($type=1){
		$shop_id = request()->shopId;
		try {
			$model = model('user_member_card');
			$model = $model->with('levelInfo');
			$model = $model->field('id,level,code,password,balance,balance_gift,integral,remark');
			$model = $model->field('count(*) as num');
			$model = $model->where('is_del',0);
			$model = $model->where('status',$type == 2 ? 1 : 0);
			$model = $model->where(function ($query) use($shop_id) {
				$query->where('apply_shop_ids','');
				$query->whereor([['','exp',\Db::raw("find_in_set($shop_id,apply_shop_ids)")]]);
			});
			$model = $model->group('batch_no');
			$data = $model->select();
			return $this->ReSucess($data);	
		} catch (\Exception $e) {
			return $this->ReError($e->getMessage());	
		}
	}
	
	
	/**
	* 明细
	* /app/v1/member_card/read
	* 需要登录 
	* @is_need_login true
	*/
	public function read($id){
		try {
			$model = model('user_member_card');
			$model = $model->with('levelInfo');
			$model = $model->field('level,code,password,balance,balance_gift,integral,remark');
			$model = $model->field('count(*) as num');
			$model = $model->where('id',$id);
			$model = $model->group('batch_no');
			$data = $model->find();
			return $this->ReSucess($data);	
		} catch (\Exception $e) {
			return $this->ReError($e->getMessage());	
		}
	}
	
}



